package org.dyndns.opendemogroup.optimizer.operations;

import org.dyndns.opendemogroup.optimizer.Member;

/**
 * Based on "inversion", described on slide 21 of <code>crossover.pdf</code>.
 */
public class InversionMutator extends OrderPreservingOperationBase
{

	@Override
	void perform ( Member parentOne, Member parentTwo, Member child, int a,
			int b )
	{
		final int length = parentOne.getMemberSize ( );
		for ( int i = 0; i < a; i++ )
		{
			final double allele = parentOne.genome[i];
			child.genome[i] = allele;
		}
		for ( int i = a, j = b - 1; i < b; i++, j-- )
		{
			final double allele = parentOne.genome[j];
			child.genome[i] = allele;
		}
		for ( int i = b; i < length; i++ )
		{
			final double allele = parentOne.genome[i];
			child.genome[i] = allele;
		}

	}
}
